// RHSPIDriver.h
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2014 Mike McCauley
// $Id: RHSPIDriver.h,v 1.16 2020/06/15 23:39:39 mikem Exp $

#ifndef RHSPIDriver_h
#define RHSPIDriver_h

#include "RHGenericDriver.h"
#include "RHHardwareSPI.h"

#define RH_SPI_WRITE_MASK 0x80

class RHGenericSPI;

class RHSPIDriver : public RHGenericDriver
{
public:
  RHSPIDriver(uint8_t slaveSelectPin = SS, RHGenericSPI& spi = hardware_spi);
  int init();
  uint8_t spiRead(uint8_t reg);
  uint8_t spiWrite(uint8_t reg, uint8_t val);
  uint8_t spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);
  uint8_t spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len);
  void setSlaveSelectPin(uint8_t slaveSelectPin);
  void spiUsingInterrupt(uint8_t interruptNumber);

protected:
  virtual void selectSlave();
  virtual void deselectSlave();
  RHGenericSPI& _spi;
  uint8_t _slaveSelectPin;
};

#endif
